package com.woniu40.petai_user.web;

import com.github.pagehelper.PageInfo;
import com.woniu40.petai_user.entity.Hospital;
import com.woniu40.petai_user.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("hospital")
public class HospitalController {

    @Autowired
    HospitalService hospitalService;

    //分页模糊查询所有医院
    @RequestMapping("/list")
    @ResponseBody
    public PageInfo<Hospital> findAll(String hospitalName, @RequestParam(defaultValue = "1") Integer pageNum, Map map) {
        if ("null".equals(hospitalName)) {
            hospitalName = "";
        }
        PageInfo<Hospital> all = hospitalService.findAll(hospitalName, pageNum, 3);
        return all;
    }

    //查询单个医院
    @RequestMapping("/hos")
    public String findHos(Integer hospitalId, Map map, HttpSession session){
        Hospital hospital = hospitalService.findHospital(hospitalId);
        session.setAttribute("hospitalId",hospitalId);
        map.put("hospital",hospital);
        return "forward:/findMap";
    }

}
